<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>手风琴效果</title>
    <style>
        * {
            list-style: none;
            margin: 0;
            padding: 0;
        }
        ul {
            margin: 30px auto;
            width: 200px;
        }
        li {
            height: 36px;
            overflow: hidden;
            margin: 10px 0;
            transition: 500ms;
        }
        h1, h2 {
            cursor: pointer;
            font-size: 30px;
            height: 36px;
            line-height: 36px;
        }
        h2 {
            margin-left: 30px;
            font-size: 20px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <ul>
        <li>
            <h1>一级标题</h1>
            <h2>二级标题</h2>
            <h2>二级标题</h2>
            <h2>二级标题</h2>
        </li>
        <li>
            <h1>一级标题</h1>
            <h2>二级标题</h2>
        </li>
        <li>
            <h1>一级标题</h1>
            <h2>二级标题</h2>
        </li>
    </ul>
    <script>
        let allLi = document.querySelectorAll("li")
        allLi.forEach(item=>{

            item.addEventListener("click", function(){
                allLi.forEach(li=>{
                    li.style.height = "36px"
                })
                console.log(this.children)
                let height = this.children.length*46-10;
                item.style.height = height+"px";
            })

        })
    </script>
</body>
</html>